import { queryPackageByLevel } from '@/api/old';
import { generateOptionsAndMap } from '@/tools/enum'
import type { MutipleType } from '@/types';
import type { SelectMap, SelectOption } from '@/types/option';
import { defineStore } from 'pinia';
import { ref } from 'vue';

export const usePackageStore = defineStore('package-info', () => {
	const packages = ref<SelectOption[]>([]);
	const packagesMap = ref<SelectMap>(new Map());

	function setPackageByLevel(level: MutipleType) {
		queryPackageByLevel(level).then((res) => {
			const { options, map } = generateOptionsAndMap(res.Data?.Packages);
			packages.value = options;
			packagesMap.value = map;
		});
	};

	return {
		packages,
		setPackageByLevel,
		packagesMap
	}
});
